﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace eGrocery.LocationDAL
{
    public class LocationDA 
    {

        //public override LocationEntity.Location SaveObject(string userName, LocationEntity.Location tObject)
        //{

        //    try
        //    {
        //        GetNewDBHelper();
        //        dbHelper.AddParameter("@ID", tObject.ID);
        //        dbHelper.AddParameter("@LOCATION_FULL_NAME", tObject.FullName);
        //        dbHelper.AddParameter("@LOCATION_DISPLAY_NAME", tObject.DisplayName);
        //        dbHelper.AddParameter("@COUNTRY_ID", tObject.Country.ID);
        //        dbHelper.AddParameter("@STATE_ID", tObject.State.ID);
        //        dbHelper.AddParameter("@CITY_ID", tObject.FullName);
        //        dbHelper.AddParameter("@ZIP_CODE", tObject.ZipCode);
        //        dbHelper.AddParameter("@ISLIVE", tObject.IsLive);
        //        dbHelper.AddParameter("@Creation_Date", tObject.CreationDate);
        //        dbHelper.AddParameter("@Created_By", tObject.CreatedBy);
        //        dbHelper.AddParameter("@Modification_Date", tObject.ModificationDate);
        //        dbHelper.AddParameter("@Modified_By", tObject.ModifiedBy);
        //        //dbHelper.ExecuteNonQuery("USP_INS_UPDATE_LOCATION", System.Data.CommandType.StoredProcedure, System.Data.ConnectionState.Closed);
        //        object objID = dbHelper.ExecuteScaler("USP_INS_UPDATE_LOCATION", System.Data.CommandType.StoredProcedure, System.Data.ConnectionState.Closed);

        //        if (Convert.ToInt32(objID) > 0)
        //            tObject.ID = Convert.ToInt32(objID);

        //        LogActivity(userName, string.Format("Product Saved with ID {0}", tObject.ID), tObject);

        //        return tObject;
            
            
            
        //    }
        //    catch (Exception)
        //    {

        //        ////throw;
        //    }
        //    return tObject; 
               
            
        //    //throw new NotImplementedException();
        //}

        //public override bool DeleteObject(string userName, LocationEntity.Location tObject)
        //{
        //    try
        //    {
        //        GetNewDBHelper();
        //        dbHelper.AddParameter("@LocationID", tObject.ID);
        //        dbHelper.ExecuteNonQuery("USP_INS_DELETE_LOCATION", System.Data.CommandType.StoredProcedure, System.Data.ConnectionState.Closed);
        //        // throw new NotImplementedException();
        //        return tObject.IsLive;

        //    }
        //    catch
        //    {
        //        return tObject.IsLive;
        //    }
        //}

        //public override List<LocationEntity.Location> GetObjectList(string userName, DateTime fromDate, DateTime toDate)
        //{
        //    throw new NotImplementedException();
        //}

        //public override List<LocationEntity.Location> SearchObject(string userName, string SearchText)
        //{
        //    try
        //    {
        //        dbHelper.AddParameter("@SearchText", string.IsNullOrWhiteSpace(SearchText) ? string.Empty : SearchText);
        //        var reader = dbHelper.ExecuteReader("USP_SEARCH_LOCATION", System.Data.CommandType.StoredProcedure, System.Data.ConnectionState.Closed);
        //        var list = new List<LocationEntity.Location>();
        //        while (reader.Read())
        //        {
        //            list.Add(GetLocationObject(reader, true));
        //        }
        //        LogActivity(userName, string.Format("Searched location with text {0}", SearchText), null);
        //        return list;
        //    }
        //    catch (Exception ex)
        //    {
        //        LogException(userName, ex, null);
        //        throw new Exception("Error while searching location");
        //    }
        //   // throw new NotImplementedException();
        //}
        //public static LocationEntity.Location GetLocationObject(IDataReader reader, bool IsFull)
        //{
        //    int i = -1;
        //    LocationEntity.Location obj = new LocationEntity.Location();
        //    if (!reader.IsDBNull(++i))
        //        obj.ID = reader.GetInt32(i);
        //    if (!reader.IsDBNull(++i))
        //        obj.FullName = reader.GetString(i);
        //    if (!reader.IsDBNull(++i))
        //        obj.DisplayName = reader.GetString(i);

        //    if (IsFull)
        //    {
        //        i += 1;
        //        if (!reader.IsDBNull(i) && !reader.IsDBNull(i + 1))
        //            obj.Country = new  LocationEntity.Country { DisplayName = reader.GetString(++i) };
        //        if (!reader.IsDBNull(i) && !reader.IsDBNull(i + 1))
        //            obj.State = new LocationEntity.State { DisplayName = reader.GetString(++i) };


        //        if (!reader.IsDBNull(i) && !reader.IsDBNull(i + 1))
        //            obj.City = new LocationEntity.City { DisplayName = reader.GetString(++i) };


        //         if (!reader.IsDBNull(++i))
        //            obj.ZipCode = reader.GetString(i);
        //        if (!reader.IsDBNull(++i))
        //            obj.IsLive = reader.GetBoolean(i);
        //    }
        //    return obj;
        //}
    }
}
